package com.dxy.lc.socketio;

import java.util.Set;

public interface ISessionService {

    void addSession(ISession session);

    ISession getSessionById(String sessionId);

    void removeSession(String sessionId);

    default void removeSession(ISession session){
        if (session != null){
            removeSession(session.getSessionId());
        }
    }

    void removeSessionByUserId(String userId);

    void removeSessionByRoomId(String roomId);

    void removeSessionByTag(String tag);

    void setUserBind(String userId, String sessionId);

    void setRoomBind(String roomId, String sessionId);

    void setTagBind(String tag, String sessionId);

    Set<String> getUserBind(String userId);

    Set<String> getRoomBind(String roomId);

    Set<String> getTagBind(String tag);

    void removeUserBind(String userId, String sessionId);

    void removeRoomBind(String roomId, String sessionId);

    void removeTagBind(String tag, String sessionId);

    default void sendMessage(ISession session, String event, Object payload) {
        if (session != null){
            session.sendMessage(event, payload);
        }
    }

    default void sendMessage(String sessionId, String event, Object payload){
        ISession session = getSessionById(sessionId);
        sendMessage(session, event, payload);
    }

    void sendMessageToLoginUsers(String event, Object payload);

    void sendMessageByUserId(String userId, String event, Object payload);

    void sendMessageByRoomId(String roomId, String event, Object payload);

    void sendMessageByTag(String tag, String event, Object payload);

    void sendMessageByTags(Set<String> tags, String event, Object payload);
}
